package leetcode;

import java.util.HashMap;
import java.util.Map;

public class l0387_字符串中的第一个唯一字符 {

    public int firstUniqChar(String s) {
        if (s == null || s.isEmpty()) {
            return -1;
        }
        char[] charArray = s.toCharArray();
        Map<Character, Integer> dataMap = new HashMap<>();
        for (char character : charArray) {
            Integer count = dataMap.getOrDefault(character, 0);
            dataMap.put(character, count + 1);
        }
        for (int i = 0; i < charArray.length; i++) {
            if (dataMap.get(charArray[i]) == 1) {
                return i;
            }
        }
        return -1;
    }
}

